import java.util.Arrays;
import java.util.Scanner;


public class Test9 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int sum = scanner.nextInt();
        int jz = scanner.nextInt();
        if(sum == 0){
            System.out.println(0);
            return;
        }
        //p是临时的变量
        StringBuilder stringBuilder = new StringBuilder();
        int p = 0;
        if(sum > 0){
            while (sum != 0){
                p = sum % jz;
                if(p >= 10) {
                    char c = (char) (55+p);
                    stringBuilder.append(c);
                }else {
                    stringBuilder.append(p);
                }
                sum /= jz;
            }
            System.out.println(stringBuilder.reverse());
        }else {
            //考虑负数
            int[]array = new int[32];
            int i = 0;
            //每一位都是指定的进制数
            sum*=-1;
            while (sum != 0){
                p = sum % jz;
                //取反
                array[i++] = jz-1-p;
                sum /= jz;
            }
            for (; i <32 ; i++) {
                //剩余的值取反
                array[i] = jz-1;

            }
            int left = 0;
            int right = array.length-1;
            while (left < right){
                //数组逆置
                swap(array,left++,right--);
            }
            int sumPlus = 0;
            //符号为不变
            //反码+1等于补码
            array[31] += 1;
            //注意j>0而不是j>=0,这样的话,可以给数组的[0]元素留出判断和修改的机会
            for (int j = 31; j > 0 ; j--) {
                //符合条件就进1
                if( array[j] == jz){
                    array[j-1]++;
                    array[j] =0;
                }
                if(array[j] >= 10) {
                    char c = (char) (55+array[j]);
                    stringBuilder.append(c);
                }else {
                    stringBuilder.append(array[j]);
                }
            }
            //为了防止二进制数的符号为1,被++成2
            if(array[0] == jz) {
                //如果++成2就改回1
                array[0]-=1;
            }
            //如果大于等于10就改为字母
                if(array[0] >= 10) {
                    char c = (char) (55+array[0]);
                    stringBuilder.append(c);
                }else {
                    //小于则不变
                    stringBuilder.append(array[0]);
                }
        //最后逆置字符串
            System.out.println(stringBuilder.reverse());

        }
    }

    private  static void swap(int[]array,int left, int right) {
          int tmp = array[left];
          array[left] = array[right];
          array[right] = tmp;
    }

}
